package models

import (
	"time"
)

type SysUserNew struct {
	UserID       int64  `json:"user_id"`
	LoginName    string `json:"login_name"`
	Password     string `json:"password"`
	ShowName     string `json:"show_name"`
	DepID        int64  `json:"dept_id"`
	UserType     int    `json:"user_type"`
	HeadImageUrl string `json:"head_image_url"`
	UserStatus   int    `json:"user_status"`
	CreateUserID int    `json:"create_user_id"`
	UpdateUserID int    `json:"update_user_id"`

	CreateTime  time.Time `json:"create_time"`
	UpdateTime  time.Time `json:"update_time"`
	DeletedFlag int32     `json:"deleted_flag"`
}

func GetSysUserByLoginName(loginName string) (*SysUserNew, error) {
	var systemUser SysUserNew
	err := db.Where("login_name = ?", loginName).First(&systemUser).Error
	return &systemUser, err
}

func GetSysUserByUserId(id int64) (*SysUser, error) {
	var systemUser SysUser
	err := db.Preload("Authorities").Preload("Authority").Where("id = ?", id).First(&systemUser).Error
	return &systemUser, err
}

const (
	SYSUSER_STATUS_NORMAL = iota
	SYSUSER_STATUS_LOCKED
)

const (
	SYSUSER_TYPE_ADMIN    = iota // 管理员
	SYSUSER_TYPE_SYSTEM          // 系统操作员
	SYSUSER_TYPE_OPERATOR        // 普通操作员
)
